home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / we32m30d.zip / DLLCALL.ZI_ / DCTST32X.C < prev   
C/C++ Source or Header  |  1993-07-30  |  2KB  |  69 lines

  1. #include "windows.h"
  2.  
  3. // This file contains sample C code for writing a DLL that can be called
  4. // from a WIL Script file to build commands of the users own choosing.
  5. // This is the Windows NT 32 bit version
  6.  
  7.  
  8. char BugBypass[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";  //Superstitious inclusion
  9.  
  10. HINSTANCE hThisInstance;   //A place to save this DLL's instance handle
  11.  
  12.  
  13. // ************************************************************************
  14. // FUNCTION : LibMain( HANDLE, DWORD, LPVOID )
  15. // PURPOSE  : LibMain is called by Windows when
  16. //            the DLL is initialized, Thread Attached, and other times.
  17. //            Just save DLL Instance here.
  18. // ************************************************************************
  19. BOOL WINAPI LibMain( HANDLE hInst, DWORD dwReason, LPVOID lpReserved )
  20. {
  21.   hThisInstance= hInst;
  22.   UNREFERENCED_PARAMETER( dwReason   );
  23.   UNREFERENCED_PARAMETER( lpReserved );
  24.   return( TRUE );
  25. }
  26.  
  27. /************************************************************************/
  28.  
  29. // MyEntryPoint - the same as the second parameter of the DllCall statement
  30. GLOBALHANDLE WINAPI MyEntryPoint(HWND hWnd,LPSTR szParams)
  31. {
  32. char szAns[128];
  33. int i;
  34. GLOBALHANDLE ghTemp;
  35. LPSTR lpTemp;
  36.  
  37.  
  38. // Display message box showing passed parameters  (szParams) wich is the
  39. // third argument of the DllCall statement
  40.  
  41. MessageBox(hWnd,szParams,"DLL CALL TEST - Passed info is",MB_OK);
  42.  
  43.  
  44.  
  45. // And now to show how to get a string back to a WIL variable.  Only strings
  46. // may be returned.  If you need to return a number....convert it to a
  47. // string first.
  48.  
  49.  
  50. // First of all manufacture an answer.  We just load it from the RC file
  51. i=LoadString(hThisInstance,1,szAns,sizeof(szAns));
  52.  
  53. // Then GlobalAlloc a memory buffer ONE BIGGER than the string
  54. ghTemp=GlobalAlloc(GMEM_MOVEABLE,(DWORD)i+1);
  55.  
  56. if (ghTemp)                      // And if it was properly allocated
  57.     {
  58.     lpTemp=GlobalLock(ghTemp);   // Lock it down and get a memory address
  59.     if (lpTemp)                  // And if that worked,
  60.        {
  61.        lstrcpy(lpTemp,szAns);    // Copy our answer to GlobalMemory
  62.        GlobalUnlock(ghTemp);     // Unlock the buffer
  63.        }
  64.     }
  65. return ghTemp;   //Return unlocked buffer.  WIL will free GlobalFree buffer
  66. }
  67.  
  68.  
  69.